using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class chat : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null) Response.Redirect(@"./getin.aspx");

        AjaxPro.Utility.RegisterTypeForAjax(typeof(chat));

        lblInfo.Text = "Welcome " + ((User)Session["user"]).UserName
            + @"<br /> from " + ((User)Session["user"]).Location.City +
            ", " + ((User)Session["user"]).Location.State;
        Label1.Text = GetMessages();
    }


    [AjaxPro.AjaxMethod]
    public string GetMessages()
    {
        GridPool upool = (GridPool)Application["UserPool"];
        User user = (User)Session["user"];
        return
            ChatEngine.GetMessages(
                upool, 
                user, ((User)Session["user"]).LastCommunicated);
        return "hello";
    }

    [AjaxPro.AjaxMethod]
    public void SendMessage(string msg)
    {
        ChatEngine.SendMessage(msg, 
            (GridPool)Application["UserPool"], 
            (User)Session["user"]);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = GetMessages();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        SendMessage(TextBox1.Text);
        TextBox1.Text = null;
        Label1.Text = GetMessages();
    }
}
